package com.ljx.offer;

/**
 * @author 李捷禧
 * Date: 2023/4/4
 * ClassName: C_
 */

public class C_33 {

    /**
     * m是树根
     * @param postorder
     * @return
     */
        public boolean verifyPostorder(int[] postorder) {
            return recur(postorder, 0, postorder.length - 1);
        }
        boolean recur(int[] postorder, int i, int j) {
            if(i >= j) return true;
            int p = i;
            while(postorder[p] < postorder[j]) p++;
            int m = p;
            while(postorder[p] > postorder[j]) p++;
            return p == j && recur(postorder, i, m - 1) && recur(postorder, m, j - 1);
        }
    }


